export default {
    //添加到购物车
    add(state, { id }) {
        let record = state.added.find(n => n.id == id);
        if (!record) {
            state.added.push({
                id,
                num: 1
            })
        } else {
            record.num++
        }
        console.log(record, state.added)
    },
    //从购物车清空
    clearALl(state) {
        state.added = []
    },
    //删除制定项目
    del(state, product) {
        state.added.forEach((n, i) => {
            console.log(product.id);
            if (n.id == product.id) {
                state.added.splice(i, 1);
            }
        })
    },
}